<?php

namespace App\Models;

use App\ModelFilters\QHSchoolArticleFilter;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Qh_SchoolArticle extends BaseModel
{
    protected $table = 'qh_school_articles';

    protected $appends = ['pushDate', 'isSchoolArticle'];

    protected $guarded = [];

    public function getPushDateAttribute() {
        if (!$this->created_at) return '';
        return Carbon::make($this->created_at)->format('Y-m-d');
    }

    public function modelFilter(): ?string
    {
        return $this->provideFilter(QHSchoolArticleFilter::class);
    }

    public function school(): BelongsTo
    {
        return $this->belongsTo(Qh_School::class, 'schoolId');
    }

    public function getIsSchoolArticleAttribute() {
        return true;
    }

    public function getCreatedAtAttribute($v) {
        return Carbon::parse($v, 'UTC')->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
    }
}
